﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GameServer.Backend;

namespace GameServer
{
    public partial class MainForm : Form
    {
        GameServer.Backend.GameServer m_Server;

        public MainForm()
        {
            InitializeComponent();
            this.Text = "Game Server Version: " + Application.ProductVersion;

            m_Server = GameServer.Backend.GameServer.GetInstance();

            //Subscribe to events.
            m_Server.OnDebug += new Action<string>(m_Server_OnDebug);
            m_Server.OnLog += new Action<string>(m_Server_OnLog);
        }

        void m_Server_OnLog(string obj)
        {
            //Make sure to marshal other threads to gui thread.
            if (this.InvokeRequired)
            {
                this.Invoke(new Action<string>(m_Server_OnDebug), obj);
                return;
            }

            textBox1.Text += obj;
        }

        void m_Server_OnDebug(string obj)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action<string>(m_Server_OnDebug), obj);
                return;
            }

            textBox1.Text += obj;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_Server.Start(50000);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            m_Server.Stop();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            m_Server.Restart();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            GameServer.Backend.GameServer.GetInstance().AccountMgr.ParsePacket(null, null);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_Server.Stop();
            this.Close();
        }
    }
}
